/**
 * Copyright (C) 2013 The yydorid-framework project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.yangying.androidframework.util;


import net.yangying.androidframework.R;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

/**
 * Acts as an interface to the TabSpec class for setting the content view. The
 * level 3 SDK doesn't support setting a View for the content sections of the
 * tab, so we can only use the big native tab style. The level 4 SDK and up
 * support specifying a custom view for the tab.
 * 
 */ 
public abstract class TabsUtil {

	public static  final String TAB ="tab";
	
    //inflate tab.xml
    public static void prepareTabView(Context context,TabSpec spec ,int drawable ,String title)
    {
    	View localView = LayoutInflater.from(context).inflate(R.layout.main_tab_item, null);  
        ((ImageView)localView.findViewById(R.id.iv_main_tab_item_image)).setBackgroundResource(drawable);  
        ((TextView)localView.findViewById(R.id.tv_main_tab_item_text)).setText(title); 

        spec.setIndicator(localView);  
    }
    /**
     * addTab
     * @param host
     * @param title
     * @param drawable
     * @param index
     * @param intent
     */
    public static void addTab(TabHost host, String title, int drawable, int index, Intent intent) {
        TabHost.TabSpec spec = host.newTabSpec(TAB + index);
        spec.setContent(intent);
        prepareTabView(host.getContext(),spec,drawable,title);
        host.addTab(spec);
    }

}
